 <div class="row">
    <div class="dropdown mb-2">
        {% if site.versioning %}
            <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            {{ page.version }}
            </button>
            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
            {% assign original_version = page.version | prepend: '/' | append: '/' %}
            {% assign latest_url = page.url | replace: page.version, site.latest | relative_url %}

            {% for version in site.versions %}
              {% assign new_version = version | prepend: '/' | append: '/' %}
              {% assign new_url = page.url | replace: original_version, new_version | relative_url %}

              {% assign target_page = site.pages | where: "url", new_url | first %}
              {% unless target_page %}
                {% assign target_prefix = page.url | split: page.version | first %}
                {% assign new_url = target_prefix | append: site.latest | append: '/' | relative_url %}
              {% endunless %}

              <a class="dropdown-item" href="{{ new_url }}">{{ version }}</a>

            {% endfor %}
            </div>
        {% else %}
            <span>{{ site.latest }}</span>
        {% endif %}
    </div>
</div>
